function [R,R1,r] = switch_schemenumber_alt(schemenumber,nf,n,nglobmonthly,nlocmatrix,s,trend)

switch schemenumber

    case 1  % Bai-Wang DFM 2
    
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(1:nf,1:nf) = ones(nf,nf);
%     R1(1,:) = 1;
%     R1([1,4,5],2:end) = 1;
    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';

    EYE = eye(nf);
    r = vec(EYE);
    case 11  % Bai-Wang DFM 2
    
    R1 = zeros(n,(nf)*(s+1));          %0=free
%     R1(:,1) = 1;
    R1(1:(nf-trend),trend+1:nf) = triu(ones(nf-trend),1)+eye(nf-trend);
    
    R3 = R1;
    
    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';

    R4 = zeros(n,(nf)*(s+1));
    R4(:,1) = 1;
    R4(1:(nf-trend),trend+1:nf) = tril(ones(nf-trend),-1)+eye(nf-trend);
    
    
    r = vec(R4');
    r(vec(R3')==0) = [];
    
    case 3
              
       restindex = ones((n-nf)*nf,1); 

       jj=0;
       for j=1:nf
        restindex((n-nf)*j+1:(n-nf)*j+nglobmonthly,1) = zeros(nglobmonthly,1);
        
        startpoint = (n-nf)*(j-1) + nglobmonthly+1+jj;
        endpoint = (n-nf)*(j-1) + nglobmonthly+nlocmatrix(j,2)+jj;
                
        restindex(startpoint:endpoint,1) = zeros(nlocmatrix(j,2),1);
        jj=jj+nlocmatrix(j,2);
       end
       
       R1 = [ones(nf); reshape(restindex,(n-nf),nf)];
       
       R1 = R1';
       R1 = R1(:);

       R2 = eye(n*nf*(s+1));
       R = R2(:,logical(R1))';
       
       r = [vec(eye(nf)); zeros((n-nf)*(nf-1),1)];
   
    case 35 % Case 3 with trends
              
       restindex = ones((n-(nf/2))*(nf/2),1); 

       jj=0;
       for j=1:(nf/2)
        restindex((n-(nf/2))*j+1:(n-(nf/2))*j+nglobmonthly,1) = zeros(nglobmonthly,1);
        
        startpoint = (n-(nf/2))*(j-1) + nglobmonthly+1+jj;
        endpoint = (n-(nf/2))*(j-1) + nglobmonthly+nlocmatrix(j,2)+jj;
                
        restindex(startpoint:endpoint,1) = zeros(nlocmatrix(j,2),1);
        jj=jj+nlocmatrix(j,2);
       end
       
       R1 = [ones(n,nf/2) [ones(nf/2); reshape(restindex,(n-(nf/2)),(nf/2))]];
       
       R1 = R1';
       R1 = R1(:);

       R2 = eye(n*nf*(s+1));
       R = R2(:,logical(R1))';
       
       r = [vec([eye(nf/2);eye(nf/2)]); zeros(((n-nf/2)*(nf/2))+(n-nf/2)*(nf/2-1),1)];    
    
    case 5  % Bai-Wang DFM 2
        
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(1,trend+1) = 1;
    R1(:,1:trend) = 1;
    R3 = R1;
    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';
    
    EYE = eye(trend);
    
    R4 = zeros(n,(nf)*(s+1));
    R4(1:trend,1:trend)=EYE;
%     R4(2,1) = 1;
    R4(1,trend+1) = 1;
    r = vec(R4');
    r(vec(R3')==0) = [];
    

%     r = [vec(EYE(1,:)); ones(nf-trend,1); vec(EYE(2:end,:)'); vec(zeros(n-trend,trend))];
%     r = [ones(nf,1); zeros(s,1); zeros((n-1)*(s+1),1)];
    case 51  % Bai-Wang DFM 2
    
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(:,1:trend+1:end) = 1;

    R1(1,trend+1) = 1;
    R3 = R1;
    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';
        
    R4 = zeros(n,(nf)*(s+1));
    R4(1:2,1) = 1;
    R4(1,trend+1) = 1;
    
    r = vec(R4');
    r(vec(R3')==0) = [];

    case 52  % Bai-Wang DFM 2
    
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(1,trend+1) = 1;
    R1(1,:) = 1;    
    R1(:,1:2:end) = 1;
    R3 = R1;
    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';
    
    EYE = eye(trend);
    
    R4 = zeros(n,(nf)*(s+1));
    R4(1:trend,1:trend)=EYE;
    R4(2,1) = 1;
    R4(3,1:2) = 1;
    R4(1,trend+1) = 1;
    r = vec(R4');
    r(vec(R3')==0) = [];

%     r = [ones(nf,1); zeros(s,1); 1; zeros(s*2,1); zeros((n-2)*(s+1),1)];
%     r = [1; zeros(s*nf,1); 1; zeros(s*2,1); zeros((n-2)*(s+1),1)];

    case 6  % China
    
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(1,:) = 1;
    R1(:,1) = 1;
%     R1(2:end-3,2) = 1;
    R1(2:end,2) = 1;
    
    R1 = R1';
    R1 = R1(:);
    
    R = eye(2);
    for jj = 1:n-1 
        R = blkdiag(R,[1 -1]);      
    end
%     for jj = 1:11 
%         R = blkdiag(R,[1 0]);      
%     end  

    r = [1;1; zeros(n-1,1)];
    
    case 7  % Brazil
    
   
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(1,:) = 1;
    R1(2:3,1:2) = 1;
    R1(:,1:2) = 1;
    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';

    r = [1 0 1 0 1 0 1 zeros(1,(n-3)*2)]';
    
    
    case 8  % India
    
   
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(1:2,:) = 1;
    R1(:,1) = 1;
    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';

    r = [1 1 1 1 zeros(1,(n-2))]';    
    
    
    case 13
        
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(1,end-1:end) = [1 1];

    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';

    r = [1; 0];
    
            case 201
        
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(1,:) = 1;
    R1(2:2,1:2) = 1;
    R1(:,1:2) = 1;
    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';

    r = [1 1 1 0 1 zeros(1,(n-2)*2)]';
    
        case 202
        
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(1,:) = 1;
    R1(2:3,1:2) = 1;
    R1(:,1:2) = 1;
    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';

    r = [1 1 1 1 1 0 1 zeros(1,(n-3)*2)]';
    
    
        case 2001
            
        R1 = zeros(n,(nf)*(s+1));          %0=free
        R1(1,:) = 1;    
        R1(:,1:trend) = 1;
        R3 = R1;
        R1 = R1';
        R1 = R1(:);

        R2 = eye(n*nf*(s+1));
        R = R2(:,logical(R1))';

        R4 = zeros(n,(nf)*(s+1));
        R4(1:2,:)=1;
        R4(3,1) = 1;
        R4(4,3) = 1;
        r = vec(R4');
        r(vec(R3')==0) = [];
        
        case 20012
            
        R1 = ones(n,(nf)*(s+1));          %0=free
        R1(:,trend+1:trend+1:end) = 0;
        
        R1(1:2,1:trend+1) = 1;    
        R3 = R1;
        R1 = R1';
        R1 = R1(:);

        R2 = eye(n*nf*(s+1));
        R = R2(:,logical(R1))';

        R4 = zeros(n,(nf)*(s+1));
        R4(1:3,1:nf)=1;
        R4(4,1) = 1;
        R4(5,3) = 1;
        r = vec(R4');
        r(vec(R3')==0) = [];        
    
        case 2002
            
        R1 = zeros(n,(nf)*(s+1));          %0=free
        R1(1,:) = 1;  
        R1(1,2) = 0;
        R1(:,1:trend) = 1;
        R3 = R1;
        R1 = R1';
        R1 = R1(:);

        R2 = eye(n*nf*(s+1));
        R = R2(:,logical(R1))';

        R4 = zeros(n,(nf)*(s+1));
        R4(1:2,:)=1;
        R4(3,1) = 1;
        R4(4,3) = 1;
        r = vec(R4');
        r(vec(R3')==0) = [];    
    
    
        case 2022
        
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(1,:) = 1;
    R1(2:3,1:2) = 1;
    R1(:,1:2) = 1;
    R1(3,1) = 0;
    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';

    r = [1 1 1 1 1 1 zeros(1,(n-3)*2)]';    
    
    case 2021
        
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(1,1:3) = 1;
    R1(2:3,1:2) = 1;
    R1(:,1:2) = 1;
    R1(5:end,4:end) = 1;
    R3 = R1;
    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';
    
    R4 = zeros(n,(nf)*(s+1));
    R4(1:3,1:3)=[1 1 1; 1 1 0; 0 1 0];
    r = vec(R4');
    r(vec(R3')==0) = [];
    
            case 203
        
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(1:2,:) = 1;
    R1(3:4,1:2) = 1;
    R1(:,1:2) = 1;
    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';

    r = [1 1 1 1 1 1 1 1 0 1 zeros(1,(n-4)*2)]';
    
                case 204 % Spain
        
    R1 = zeros(n,(nf)*(s+1));          %0=free
    R1(1,:) = 1;
    R1(2:3,1:2) = 1;
    R1(:,1:2) = 1;
    R1 = R1';
    R1 = R1(:);

    R2 = eye(n*nf*(s+1));
    R = R2(:,logical(R1))';

    r = [1 1 1 1 1 0 1 0 0 0 1 zeros(1,(n-5)*2)]';
    
end